package net.sf.jOpinionPoll.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.TableGenerator;

@Entity
@Table(name = "alternativa")
@NamedQueries( {
		@NamedQuery(name = "Alternativa.fetch.findById", query = "SELECT q FROM Alternativa q WHERE q.id = :id"),
		@NamedQuery(name = "Alternativa.findAll", query = "SELECT q FROM Alternativa q"),
		@NamedQuery(name = "Alternativa.count", query = "SELECT COUNT(q) FROM Alternativa q") })
public class Alternativa implements Serializable {
	private static final long serialVersionUID = 1L;
	private int id;
	private String descricao;

	public Alternativa() {
	}

	public Alternativa(String descricao) {
		setDescricao(descricao);
	}

	@Id
	@Column(name = "id")
	@TableGenerator(name = "alternativaGen", table = "sequence_generator_table", pkColumnName = "gen_key", pkColumnValue = "alternativa_id", valueColumnName = "gen_value", allocationSize = 50, initialValue = 0)
	@GeneratedValue(strategy = GenerationType.TABLE, generator = "alternativaGen")
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@Column(name = "descricao", nullable = true, length = 255)
	public String getDescricao() {
		return descricao;
	}

	public void setDescricao(String descricao) {
		this.descricao = descricao;
	}

	@Override
	public int hashCode() {
		return getId();
	}

	@Override
	public boolean equals(Object o) {
		if (o == null || !(o instanceof Alternativa))
            return false;

        if (getId() != 0)
	        return (getId() == ((Alternativa)o).getId());
        
        return this == o;
	}

	@Override
	public String toString() {
		return this.getClass().getName() + "[pk=" + getId() + "]";
	}
}